package com.judian.smart.proxy;

import com.judian.smart.db.Database;
import com.judian.smart.db.WidgetDAOImpl;
import com.judian.smart.interfaces.IWidgetDAO;
import com.judian.smart.model.Device;
import com.judian.smart.model.DeviceType;
import com.judian.smart.model.Floor;
import com.judian.smart.model.GateWay;
import com.judian.smart.model.GatewayType;
import com.judian.smart.model.Mode;
import com.judian.smart.model.ModeList;
import com.judian.smart.model.Products;
import com.judian.smart.model.RedInfra;
import com.judian.smart.model.Room;
import com.judian.smart.model.VoiceInfo;

import java.util.List;

/**
 * author: Peter
 * date: 2019/08/09 星期五 10:55
 * desc:
 */
public class WidgetDAOProxy implements IWidgetDAO {
    private static Database dba;
    public static IWidgetDAO dao;
    public static WidgetDAOProxy instance;

    static {
        instance = new WidgetDAOProxy();
        dba = new Database();
        dao = new WidgetDAOImpl(dba.getSQLiteDatabase());
    }

    public static WidgetDAOProxy getInstance() {
        if (instance == null) {
            instance = new WidgetDAOProxy();
            dba = new Database();
            dao = new WidgetDAOImpl(dba.getSQLiteDatabase());
        }
        return instance;
    }


    @Override
    public List<GateWay> getGateWay() {
        return dao.getGateWay();
    }

    @Override
    public List<GatewayType> getGateWayType() {
        return dao.getGateWayType();
    }

    @Override
    public List<Mode> getMode() {
        return dao.getMode();
    }

    @Override
    public List<ModeList> getModeList() {
        return dao.getModeList();
    }

    @Override
    public List<Room> getRoom() {
        return dao.getRoom();
    }

    @Override
    public List<DeviceType> getDeviceTypes() {
        return dao.getDeviceTypes();
    }

    @Override
    public int insertRoom(Room room) {
        return dao.insertRoom(room);
    }

    @Override
    public int insertDevice(Device device) {
        return dao.insertDevice(device);
    }

    @Override
    public int insertMode(Mode mode) {
        try {
            return dao.insertMode(mode);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int insertGateWay(GateWay gateWay) {
        try {
            return dao.insertGateWay(gateWay);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int insertModeList(ModeList modeList) {
        return dao.insertModeList(modeList);
    }

    @Override
    public int updateModeList(ModeList modeList) {
        return dao.updateModeList(modeList);
    }

    @Override
    public int updateMode(Mode mode, String modeName) {
        try {
            return dao.updateMode(mode, modeName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int updateDevice(Device device) {
        try {
            return dao.updateDevice(device);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public void updateDeviceTypeSort(List<DeviceType> list) {
        dao.updateDeviceTypeSort(list);
    }

    @Override
    public int updateGateWay(GateWay gateWay, String gateWayName) {
        try {
            return dao.updateGateWay(gateWay, gateWayName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int updateFraID(String deviceID, int infra_index) {
        try {
            return dao.updateFraID(deviceID, infra_index);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public void updateDeviceSort(List<Device> list) {
        dao.updateDeviceSort(list);
    }

    @Override
    public void updateModeSort(List<Mode> list) {
        dao.updateModeSort(list);
    }

    @Override
    public void updateRoomSort(List<Room> list) {
        dao.updateRoomSort(list);
    }

    @Override
    public void updateModeListSort(List<ModeList> list) {
        dao.updateModeListSort(list);
    }

    @Override
    public void updateDeviceType(DeviceType list) {
        dao.updateDeviceType(list);
    }

    @Override
    public int updateIsCurrent(int id, int current) {
        return dao.updateIsCurrent(id, current);
    }

    @Override
    public int updateRoom(Room room, String arceName) {
        return dao.updateRoom(room, arceName);
    }

    @Override
    public void updateRoomHide(int homePageDisplays, int id) {
        dao.updateRoomHide(homePageDisplays, id);
    }

    @Override
    public int deleteGateWay(int Id) {
        return dao.deleteGateWay(Id);
    }

    @Override
    public int deleteRoom(int id) {
        return dao.deleteRoom(id);
    }

    @Override
    public int deleteRedFra(int id) {
        return dao.deleteRedFra(id);
    }

    @Override
    public int deleteMode(int id) {
        return dao.deleteMode(id);
    }

    @Override
    public int deleteDevice(int id) {
        return dao.deleteDevice(id);
    }

    @Override
    public int deleteModelist(int id) {
        return dao.deleteModelist(id);
    }

    @Override
    public int deleteInfrad(int id) {
        return dao.deleteInfrad(id);
    }

    @Override
    public int deleteSyncData(String table) {
        return dao.deleteSyncData(table);
    }

    @Override
    public void execSQL(String sql) {
        dao.execSQL(sql);
    }

    @Override
    public List<Products> getProducts() {
        return dao.getProducts();
    }

    @Override
    public List<RedInfra> getInfrareds() {
        return dao.getInfrareds();
    }

    @Override
    public int insertVoice(VoiceInfo voiceInfo) {
        try {
            return dao.insertVoice(voiceInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public List<Device> getDevices() {
        return dao.getDevices();
    }

    public IWidgetDAO getWidgetDataBase() {
        return WidgetDAOProxy.getInstance();
    }

    public List<Floor> getFloor() {
        return dao.getFloor();
    }

    @Override
    public int insertInfrad(RedInfra infrared) {
        return dao.insertInfrad(infrared);
    }

    @Override
    public String getProductsCodeByProductsKey(int productsKey) {
        return dao.getProductsCodeByProductsKey(productsKey);
    }

    @Override
    public List<Device> getSafeDevice() {
        return dao.getSafeDevice();
    }

    @Override
    public List<Device> getModeDevice(int modeById) {
        return dao.getModeDevice(modeById);
    }

    @Override
    public void updateGatewaySort(List<GateWay> list) {
        dao.updateGatewaySort(list);
    }

    @Override
    public boolean checkColumnExist(String tableName, String columnName) {
        return dao.checkColumnExist(tableName, columnName);
    }
}
